<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>KIT ADMIN</title>
    <link rel="stylesheet" href="/statics/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/statics/plugins/font-awesome/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="/statics/src/css/app.css" media="all"/>
    <link rel="stylesheet" href="/statics/src/css/themes/default.css" media="all" id="skin" kit-skin/>
    <script src="/statics/plugins/layui/layui.js"></script>
</head>

<body>
<div>
    <form class="layui-form" style="margin-top: 20px">
        <div class="layui-form-item" align="center">
            <label for="adminName" class="layui-form-label">
                <span class="x-red">*</span>用户姓名
            </label>
            <input type="hidden" name="userId" th:value="${admin.userId}">
            <div class="layui-input-inline">
                <input type="text" id="adminName" name="adminName" th:value="${admin.adminName}"
                       required="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" align="center">
            <label for="userName" class="layui-form-label">
                <span class="x-red">*</span>登录名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userName" name="userName" required="true" th:value="${admin.userName}"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" align="center">
            <label for="password" class="layui-form-label">
                <span class="x-red">*</span>登录密码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="password" name="password" required="true" th:value="${admin.password}"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" >
            <label for="auth" class="layui-form-label">
                <span class="x-red">*</span>用户权限
            </label>
            <div class="layui-input-block" style="width: 190px">
                <select name="auth" lay-filter="auth" id="auth">
                    <option value="0" th:selected="${admin.auth=='0'}">前台权限</option>
                    <option value="1" th:selected="${admin.auth=='1'}">管理员权限</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" align="center">
            <button class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(JSON.stringify(data.field))
            //发异步
            $.post({
                dataType: 'json',
                contentType: 'application/json',
                url: "/admin/save",
                data: JSON.stringify(data.field),
                success: function (result) {
                    if (result.code == 0) {
                        layer.alert(result.msg, {
                            title: '操作成功：'
                        }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(result.msg, { time: 1000});
                    }
                },
                error: function () {
                    layer.msg('网络繁忙!', {time: 1000});
                }
            });

            return false;
        });

    });
</script>

</body>

</html>